<?php

namespace Biz\service\advertisement\apiModule;

use Doraemon\tools\BlockType;
use Doraemon\tools\ImgUrl;

class SearchResultTopBanner extends BaseModule
{

    public function formatAdmListExtInfo(&$v, $map)
    {
        $v['ext']['key_word'] = explode(',', $map[$v['id']]['key_word'] ?? '');
    }

    public function extCheckActive($v, $extInput)
    {
        $key_word = $extInput['key_word'] ?? '';
        $config = $v['ext']['key_word'] ?? '';
        $config = explode(',', $config);
        return strlen($key_word) && in_array($key_word, $config);
    }

    public function format($hit, $uid, $userProfileExt, $statSignExt)
    {

        $response = [];
        if (empty($hit)) return $response;

        if ($hit) {
            $response = array(
                "id" => $hit['id'],
                "link" => $this->generateLink($hit['link_type'], $hit['link_params']),
                'banner' => strlen($hit['pic_id']) ? ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $hit['pic_id'], ImgUrl::IMAGE_SIZE_OP_ORI) : '',
                "statType" => (string) 'search-banner-' . BlockType::TYPE_CAROUSEL_BANNER,
                "statSign" => $this->statSign($hit, $statSignExt)
            );
        }
        return $response;
    }

}